package com.zhhs.project.act.activity.controller;



import com.zhhs.common.utils.poi.ExcelUtil;
import com.zhhs.framework.aspectj.lang.annotation.Log;
import com.zhhs.framework.aspectj.lang.enums.BusinessType;
import com.zhhs.framework.web.controller.BaseController;
import com.zhhs.framework.web.domain.AjaxResult;
import com.zhhs.framework.web.page.TableDataInfo;
import com.zhhs.project.act.activity.domian.ActActivityPrize;
import com.zhhs.project.act.activity.service.IActActivityPrizeService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 派奖方式Controller
 *
 * @author peng
 * @date 2022-11-09
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wecom/activity/prize")
public class ActActivityPrizeController extends BaseController
{


    @Autowired
    private IActActivityPrizeService actActivityPrizeService;


    /**
     * 查询奖项设置列表
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityPrize:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActActivityPrize actActivityPrize)
    {
        startPage();
        List<ActActivityPrize> list = actActivityPrizeService.selectActActivityPrizeList(actActivityPrize);
        return getDataTable(list);
    }

    /**
     * 导出奖项设置列表
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityPrize:export')" )
    @Log(title = "奖项设置" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(ActActivityPrize actActivityPrize)
    {
        List<ActActivityPrize> list = actActivityPrizeService.selectActActivityPrizeList(actActivityPrize);
        ExcelUtil<ActActivityPrize> util = new ExcelUtil<ActActivityPrize>(ActActivityPrize.class);
        return util.exportExcel(list, "派奖方式数据");
    }

    /**
     * 获取奖项设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityPrize:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(actActivityPrizeService.selectActActivityPrizeById(id));
    }

    /**
     * 新增奖项设置
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityPrize:add')" )
    @Log(title = "奖项设置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addSave(ActActivityPrize actActivityPrize)
    {
        return toAjax(actActivityPrizeService.insertActActivityPrize(actActivityPrize));
    }

//    /**
//     * 修改派奖方式
//     */
//    @GetMapping("/edit/{activityId}")
//    public String edit(@PathVariable("activityId") Long activityId, ModelMap mmap)
//    {
//        ActActivityPrize actActivityPrize = new ActActivityPrize();
//        actActivityPrize.setActivityId(activityId);
//        List<ActActivityPrize> activityPrizeList = actActivityPrizeService.selectActActivityPrizeList(actActivityPrize);
//        mmap.put("actActivityPrize", activityPrizeList);
//        return prefix + "/edit";
//    }

    /**
     * 修改奖项设置
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityPrize:edit')" )
    @Log(title = "奖项设置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult editSave(ActActivityPrize actActivityPrize)
    {
        return toAjax(actActivityPrizeService.updateActActivityPrize(actActivityPrize));
    }

    /**
     * 删除奖项设置
     */
    @PreAuthorize("@ss.hasPermi('zhhs:activityPrize:remove')" )
    @Log(title = "奖项设置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String ids)
    {
        return toAjax(actActivityPrizeService.deleteActActivityPrizeByIds(ids));
    }
}
